/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.upms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.params.IdListParam;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.vo.*;
import com.mt.roll.upms.params.MenuResourceParam;
import com.mt.roll.upms.params.MenuResourceQueryParam;
import com.mt.roll.upms.service.MenuResourceService;
import com.mt.roll.upms.vo.ResourceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 平台菜单资源控制器
 *
 * @author jiff
 * @date 2018/11/14
 * @since 1.0
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_UPMS + "menuResource")
@Slf4j
@Api(value = "菜单资源管理", tags = "平台菜单资源管理接口", hidden = false)
public class MenuResourceController extends BaseController {
    @Autowired
    private MenuResourceService menuResourceService;


    @PostMapping(value = "listByMenu")
    @ApiOperation(value = "获取菜单已关联的资源列表")
    private R<List<MenuResourceVo>> listByMenu(@Validated({Default.class}) @RequestBody IdParam idParam) {
        return menuResourceService.listByMenu(idParam);
    }

    @PostMapping(value = "listWithMenu")
    @ApiOperation(value = "获取菜单未关联的资源列表，根据菜单分类返回未关联的资源列表")
    private R<List<ResourceVo>> listWithMenu(@Validated({Default.class}) @RequestBody MenuResourceQueryParam menuResourceQueryParam) {
        return menuResourceService.listWithMenu(menuResourceQueryParam);
    }

    @PostMapping(value = "pageWithMenu")
    @ApiOperation(value = "获取菜单未关联的资源分页列表，根据菜单分类返回未关联的资源列表")
    private R<PageVo<ResourceVo>> pageWithMenu(@Validated({PageGroup.class, Default.class}) @RequestBody MenuResourceQueryParam menuResourceQueryParam) {
        return menuResourceService.pageWithMenu(menuResourceQueryParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增菜单资源")
    private R<IdListVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody MenuResourceParam menuResourceParam) {
        return menuResourceService.add(menuResourceParam);
    }


    @PostMapping(value = "delete")
    @ApiOperation(value = "删除菜单资源")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return menuResourceService.delete(idParam);
    }

    @PostMapping(value = "batchDelete")
    @ApiOperation(value = "批量删除菜单资源")
    private R<IdListVo> delete(@Validated @RequestBody IdListParam idListParam) {
        return menuResourceService.delete(idListParam);
    }
}
